IF EXISTS (SELECT * FROM SYSOBJECTS WHERE ID = OBJECT_ID('SubjectInsert') AND sysstat & 0xf = 4)
    DROP PROCEDURE [SubjectInsert]
GO
CREATE PROCEDURE [SubjectInsert]
(
    @SubjectId int = null output,
    @Value nvarchar,
    @CountOfPaint int,
    @CreateDate datetime,
    @UpdateDate datetime
)
AS
BEGIN
	SET NOCOUNT ON
	INSERT INTO [subject](
        [value],
        [count_of_paint],
        [create_date],
        [update_date]
	)
	VALUES(
        @Value,
        @CountOfPaint,
        @CreateDate,
        @UpdateDate
	)
	SELECT @SubjectId = SCOPE_IDENTITY()
END
GO

IF EXISTS (SELECT * FROM SYSOBJECTS WHERE ID = OBJECT_ID('SubjectUpdate') AND sysstat & 0xf = 4)
    DROP PROCEDURE [SubjectUpdate]
GO
CREATE PROCEDURE [SubjectUpdate]
(
	@SubjectId int,
    @Value nvarchar,
    @CountOfPaint int,
    @CreateDate datetime,
    @UpdateDate datetime
)
AS
BEGIN
	
	UPDATE [subject]
	SET
        [value]=@Value,
        [count_of_paint]=@CountOfPaint,
        [create_date]=@CreateDate,
        [update_date]=@UpdateDate
	WHERE
		[subject_id] = @SubjectId

END
GO

IF EXISTS (SELECT * FROM SYSOBJECTS WHERE ID = OBJECT_ID('SubjectDelete') AND sysstat & 0xf = 4)
    DROP PROCEDURE [SubjectDelete]
GO
CREATE PROCEDURE [SubjectDelete]
(
	@SubjectId int	
)
AS
BEGIN
	
	DELETE
	FROM [subject]
    WHERE
		[subject_id] = @SubjectId
END
GO

IF EXISTS (SELECT * FROM SYSOBJECTS WHERE ID = OBJECT_ID('SubjectSelectOne') AND sysstat & 0xf = 4)
    DROP PROCEDURE [SubjectSelectOne]
GO
CREATE PROCEDURE [SubjectSelectOne]
(
	@SubjectId int
)
AS
BEGIN
	SET NOCOUNT ON	
	SELECT
		*
	FROM [subject] (NOLOCK)
	WHERE
		([subject_id] = @SubjectId)

END
GO

IF EXISTS (SELECT * FROM SYSOBJECTS WHERE ID = OBJECT_ID('SubjectSelectAll') AND sysstat & 0xf = 4)
    DROP PROCEDURE [SubjectSelectAll]
GO

CREATE PROCEDURE [SubjectSelectAll]
AS
BEGIN

	SET NOCOUNT ON
	SELECT
		subject_id AS SubjectId,
		Value
	FROM [subject] (NOLOCK)

END
GO
